using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Coffee.SurveyControls.SurveyQuestions
{

    /// <summary>
    /// Summary description for SQRadioButtonList
    /// </summary>
    public class SQRadioButtonList : SurveyQuestionRow
    {
        public SQRadioButtonList(SurveyControl parent, XmlNode configuration)
            : base(parent, configuration)
        {
        }

        public override void LoadDynamicData()
        {
            RadioButtonList rbcurr = (RadioButtonList)currentAnswerControl;
            Coffee.Binding.ConfigureBinding(rbcurr, rootNode);
            rbcurr.DataBind();
        }

        public override void LoadData()
        {
            Label tPrev = (Label)previousAnswerControl;
            RadioButtonList rbcurr = (RadioButtonList)currentAnswerControl;

            //Reload();

            if (Parent.Mapper != null)
            {
                tPrev.Text = (string)Parent.Mapper.Previous.GetProperty(ctlId);
                rbcurr.SelectedValue = (string)Parent.Mapper.Current.GetProperty(ctlId);
            }
        }

        public override void SaveData()
        {
            RadioButtonList rbcurr = (RadioButtonList)currentAnswerControl;

            if (Parent.Mapper != null)
            {
                // need to implement saving by index depending on configuration
                Parent.Mapper.Current.SetProperty(ctlId, rbcurr.SelectedValue);
            }
        }

        protected override void Initialize()
        {

        }

        protected override Control CreateCurrentDataControl()
        {
            RadioButtonList rbl = new RadioButtonList();
            rbl.ID = ctlId;
            rbl.CssClass = "question";
            return rbl;
        }

        protected override Control CreatePreviousDataControl()
        {
            Label tPrev = new Label();
            tPrev.CssClass = "question";
            return tPrev;
        }

    }
}